package com.edu.exam.enums.common;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 优先级级别枚举
 *
 * 统一的优先级管理，用于各种需要优先级控制的场景
 * 替代分散在各个实体中的重复优先级定义
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-13
 */
public enum PriorityLevel implements BaseEnum {

    /** 最低优先级 */
    LOWEST("LOWEST", "最低优先级"),

    /** 低优先级 */
    LOW("LOW", "低优先级"),

    /** 普通优先级 */
    NORMAL("NORMAL", "普通优先级"),

    /** 中等优先级 */
    MEDIUM("MEDIUM", "中等优先级"),

    /** 高优先级 */
    HIGH("HIGH", "高优先级"),

    /** 紧急优先级 */
    URGENT("URGENT", "紧急优先级"),

    /** 最高优先级 */
    HIGHEST("HIGHEST", "最高优先级"),

    /** 关键优先级 */
    CRITICAL("CRITICAL", "关键优先级");

    private final String code;
    private final String description;

    PriorityLevel(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static PriorityLevel fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("PriorityLevel code cannot be null or empty");
        }
        for (PriorityLevel priority : values()) {
            if (priority.getCode().equals(code)) {
                return priority;
            }
        }
        throw new IllegalArgumentException("Unknown PriorityLevel code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static PriorityLevel fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("PriorityLevel description cannot be null or empty");
        }
        for (PriorityLevel priority : values()) {
            if (priority.getDescription().equals(description)) {
                return priority;
            }
        }
        throw new IllegalArgumentException("Unknown PriorityLevel description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}